﻿using UnityEngine;
using System.Collections;

public class Follow : MonoBehaviour {

	public Transform target1;
	public Transform target2;

	private Vector3 offset;

	private Camera camera;
	// Use this for initialization
	void Start () {
		offset = transform.position - (target1.position+target2.position)/2;
		camera = this.GetComponent<Camera>();
	}
	
	// Update is called once per frame
	void Update () {
		if (target1 != null && target2 != null) {

			//位置
			transform.position = offset + (target1.position + target2.position) / 2;

			//摄像机视角
			float distance = Vector3.Distance (target1.position, target2.position);
			float size = (float)(distance * 0.8);
			camera.orthographicSize = size;
		} else if (target1 != null) {
			transform.position = target1.position;
			//摄像机视角
			float distance = Vector3.Distance (target1.position, Vector3.zero);
			float size = (float)(distance * 0.8);
			camera.orthographicSize = size;
		}else if (target2 != null) {
			transform.position = target2.position;
		}
	}
}
